﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Compression;
using System.IO;

namespace A2DFramework.HttpLoadBalancer.Utility
{
    public static class GZipHelper
    {
        public static string Convert(byte[] buffer)
        {
            StringBuilder s = new StringBuilder(102400);

            GZipStream g = new GZipStream((Stream)(new MemoryStream(buffer)), CompressionMode.Decompress); 

            byte[] d = new byte[20480];
            int l = g.Read(d, 0, 20480); 
            
            while (l > 0)
            {
                s.Append(Encoding.Unicode.GetString(d, 0, l)); 
                l = g.Read(d, 0, 20480);
            }
            return s.ToString();
        } 
    }
}
